var flag_puser = false;
var flag_ppwd = false;
var flag_prepwd = false;
var flag_pverifycode = false;
var flag_sameppwd = false;
var flag_verifypuserexist = false;
var flag_verifypcodeexist = false;
var flag_verifyploginexist = false;
var editor ; 
var editor2 ; 
function verifyNull(str , flag) {
	var msg = "";
	sl = flag+str;
	if ($("#" + sl).attr("value") == "") {
		switch (str) {
		case "user":
			msg =msg_puser;
			flag_puser = false;
			break;
		case "pwd":
			msg = msg_ppwd;
			flag_ppwd = false;
			break;
		case "repwd":
			msg = msg_prepwd;
			flag_prepwd = false;
			break;
		case "verifycode":
			msg = msg_pverifycode;
			flag_pverifycode = false;
			break;
		}
		$("#span_" + sl).html(msg);
		return false;
	} else {
		switch (str) {
		case "user":
			msg =msg_puser;
			flag_puser = true;
			break;
		case "pwd":
			msg = msg_ppwd;
			flag_ppwd = true;
			break;
		case "repwd":
			msg = msg_prepwd;
		    flag_prepwd = true;
			break;
		case "verifycode":
			msg = msg_pverifycode;
			flag_pverifycode = true;
			break;
		}
		msg = "";
		$("#span_" + sl).html(msg);
		return true;
	}
}

function verifySame(str1, str2) {
	str = str1 + "&" + str2;
	var msg = "";
	if ($("#" + str1).attr("value") != $("#" + str2).attr("value")) {
		switch (str) {
		case "ppwd&prepwd":
			msg = msg_pwd;
			flag_sameppwd = false;
			break;
		}
		$("#span_" + str1).html(msg);
		return false;
	} else {
		switch (str) {
		case "ppwd&prepwd":
			msg = msg_pwd;
			flag_sameppwd = true;
			break;
		}
		msg = "";
		$("#span_" + str1).html("");
		return true;
	}
}

function verifyObjectExist(id,flag ,action,data ){
	var url = "";
	var ids = id.split( ",");
	var datas = data.split(",");
	if(ids.length>1){
		if(ids.length!=datas.length){
			alert("error");
		}
		for(var i = 0; i<ids.length;i++){
			if(i>0){
				url = url+"&";
			}
			url = url+datas[i]+"="+$("#"+flag+ids[i]).attr("value")+"";
		}
	}else{
		url = data+"="+$("#"+flag+id).attr("value");
	}
	$.ajax({
		contentType : "application/x-www-form-urlencoded; charset=utf-8",
		type : "POST",// 用POST方式传输
		dataType : "json",// 数据格式:JSON
		url : action+".action",// 目标地址
		data : url,
		async: false, 
		error : function() {
			alert("jsonerror");
		},
		success : function(json) {
			str = json[0];
			if (str == "exist") {
				switch (id) {
				case "user":
					flag_verifypuserexist = false;
					$("#span_"+flag+id).html(msg_userexist);
					break;
				case "user,pwd":
					flag_verifyploginexist = true;
					$("#span_"+flag+ids[0]+flag+ids[1]).html(msg_loginexist);
					break;	
				case "verifycode":
					flag_verifypcodeexist = true;
					$("#span_"+flag+id).html(msg_verifycodeexist);
					break;
				}
			} else if (str == "notexist") {
				switch (id) {
				case "user":
					flag_verifypuserexist = true;
					$("#span_"+flag+id).html(msg_usernotexist);
					break;
				case "user,pwd":
					flag_verifyploginexist = false;
					$("#span_"+flag+ids[0]+flag+ids[1]).html(msg_loginnotexist);
					break;	
				case "verifycode":
					flag_verifypcodeexist = false;
					$("#span_"+flag+id).html(msg_verifycodenotexist);
					break;
				}
			}
		}

	});
	
}

function verifyExist(id ,flag, action , data){
	if(verifyNull(id ,flag)){
		verifyObjectExist(id,flag,action,data);
	}
}

function mysubmit_pregister() {
	verifyExist("user" ,"p", "verifyUserExist" , "user.username");
	verifyExist("verifycode" , "p","verifyCodeExist" , "otherData.verifycode");
	verifyNull("pwd", "p");
	verifyNull("repwd" , "p");
	verifyNull("verifycode" , "p");
	if (flag_ppwd && flag_prepwd) {
		verifySame("ppwd", "prepwd");
	}
	if (flag_puser&&flag_ppwd&&flag_prepwd&&flag_pverifycode&&flag_sameppwd&&flag_verifypuserexist&&flag_verifypcodeexist) {
		$('#myform').submit();
	}
}


function mysubmit_plogin() {
	verifyNull("user" , "p");
	verifyNull("pwd" , "p");
	verifyNull("verifycode" , "p");
	verifyExist("verifycode" , "p" , "verifyCodeExist" , "otherData.verifycode");
	if(flag_pverifycode&&flag_verifypcodeexist){
		verifyExist("user,pwd" ,"p", "verifyPLoginExist" , "user.username,user.password");
	}
	
	if (flag_puser&&flag_ppwd&&flag_pverifycode&&flag_verifyploginexist&&flag_verifypcodeexist) {
		$('#mypform').submit();
	}
}

function mysubmit_clogin() {
	verifyNull("user" , "c");
	verifyNull("pwd" , "c");
	verifyNull("verifycode" , "c");
	verifyExist("verifycode" ,"c", "verifyCodeExist" , "otherData.verifycode");
	if(flag_pverifycode&&flag_verifypcodeexist){
		verifyExist("user,pwd" ,"c", "verifyCLoginExist" , "user.username,user.password");
	}
	if (flag_puser&&flag_ppwd&&flag_pverifycode&&flag_verifyploginexist&&flag_verifypcodeexist) {
		$('#mycform').submit();
	}
}

function selectData(id,flag,action,data ){
	
	$.ajax({
		contentType : "application/x-www-form-urlencoded; charset=utf-8",
		type : "POST",// 用POST方式传输
		dataType : "json",// 数据格式:JSON
		url : action+".action",// 目标地址
		data : data,
		async: false,
		beforeSend : function() {
			
		},
		error : function() {
			//alert("jsonerror_select");
			window.location.replace("../login.jsp");
		},
		success : function(json) {
			$("#"+id).empty();
			if(flag=='fav-dir-sel'){
				$("#fav-dir-sel").append("<option value='addToDirectory' >"+addToDirectory+"</option>");
			}
			if(flag=='fri-dir-sel'){
				$("#fri-dir-sel").append("<option value='' >"+addToDirectory+"</option>");
			}
			$.each(
					json,
					function(i, n) {  
						if(flag=='question-right-item'){
							$("#"+id).append("<li><a style='cursor:hand' onclick = 'findQuestionByCategory("+n[1]+")'>"+n[0]+"</a></li>");
						}else if(flag=='fav-dir-list'){
							$("#"+id).append("<li><a style='cursor:hand' onclick = 'findQuestionByFavgroup("+n[1]+")'>"+n[0]+"</a></li>");
						}else if(flag=='fav-dir-sel'){
							$("#"+id).append("<option value='"+n[1]+"'>"+n[0]+"</option>");
						}else if(flag=='checkbox-user'){
							$("#"+id).append("<input type='checkbox' value='"+n[1]+"' name='checkbox_user_name'/>"+n[0]);
						}else{
							$("#"+id).append("<option value='"+n[1]+"'>"+n[0]+"</option>");
						}});
			if(flag=='fav-dir-list'){
				$("#fav-dir-list").append("<li><a style='cursor:hand' onclick = 'notFavGroup()'>"+notGroup+"</a></li>");
			}
			if(flag=='fav-dir-sel'){
				$("#fav-dir-sel").append("<option value='notGroup' >"+notGroup+"</option>");
			}
			if(flag=='fri-dir-sel'){
				$("#fri-dir-sel").append("<option value='' >"+notGroup+"</option>");
			}
			
		}
	});
}

//单个数字配零
function getDouble(number){
 var numbers=["0","1","2","3","4","5","6","7","8","9"];
 for(var i=0;i<numbers.length;i++){
  if(numbers[i]==number){
   return "0"+numbers[i];
  }else if(i==9){
   return number;
  }
  
 }
}
//得到当天时间
function getTodayTime(){
 var days=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
 var today=new Date();
 var str= (today.getYear()<1900?1900+today.getYear():today.getYear())+"年" + getDouble([today.getMonth()+1])+"月" +getDouble(today.getDate()) +"日 &nbsp;"+ days[today.getDay()]+"&nbsp;"+getDouble(today.getHours())+":"+getDouble(today.getMinutes())+":"+getDouble(today.getSeconds());
 $("#datetime").html(str);
 
}
//每隔一秒刷新一次
setInterval("getTodayTime()",1000);

function mysubmit_cjobdetail() {
	
	$('#cjobdetail').submit();
	
}

function selectDataSelected(id,flag,action,data ){
	$.ajax({
		contentType : "application/x-www-form-urlencoded; charset=utf-8",
		type : "POST",// 用POST方式传输
		dataType : "json",// 数据格式:JSON
		url : action+".action",// 目标地址
		data : "bzn_jobdescription.id="+data,
		async: false, 
		error : function() {
			alert("jsonerror");
		},
		success : function(json) {
			var str = json[0];
			
			/*bzn.title 
			bzn.cop_companyinfo.id 
			bzn.bsc_jobtype.id , 
			bzn.bsc_city.id ,
			bzn.bsc_city.bsc_region.id ,
			bzn.bsc_workyear.id , 
			bzn.bsc_salary.id ,
			bzn.bsc_educational.id , 
			bzn.numberOfRecruits ,  
			bzn.bsc_specialty.id , 
			bzn.bsc_certificate.id , 
			bzn.bsc_language.id , 
			bzn.bsc_skill.id , 
			bzn.description*/
		
			$("#inputtitle").val(str[0]);
			$("#selectcompanyinfo option[value='"+str[1]+"']").attr('selected',true);
			$("#selectjobtype option[value='"+str[2]+"']").attr('selected',true);
			$("#selectworkyear option[value='"+str[5]+"']").attr('selected',true);
			$("##selectsal option[value='"+str[6]+"']").attr('selected',true);
			$("#selecteducational option[value='"+str[7]+"']").attr('selected',true);
			$("#inputnum").val(str[8]);
			$("#selectspecialty option[value='"+str[9]+"']").attr('selected',true);
			$("#selectcertificate option[value='"+str[10]+"']").attr('selected',true);
			$("#selectlanguage option[value='"+str[11]+"']").attr('selected',true);
			$("#selectskill option[value='"+str[12]+"']").attr('selected',true);
			$("#inputjobdesc").val(str[13]);
			$("#selectworktype option[value='"+str[14]+"']").attr('selected',true);
			$("#inputcominfo").val(str[15]);
			$("#inputdate").val(str[16]);
			BindCity(str[17]);
		}
	});
}
function inputData(id,flag,action,data ){
	$.ajax({
		contentType : "application/x-www-form-urlencoded; charset=utf-8",
		type : "POST",// 用POST方式传输
		dataType : "json",// 数据格式:JSON
		url : action+".action",// 目标地址
		data : data,
		async: false, 
		error : function() {
			alert("jsonerror");
		},
		success : function(json) {
			var str = json[0];
			$("#"+id).val(str[flag]);
		}
	});
}

function insertData(id,flag,action,data ){
	var url = "";
	var ids = id.split( ",");
	var datas = data.split(",");
	if(ids.length>1){
		if(ids.length!=datas.length){
			alert("error");
		}
		for(var i = 0; i<ids.length;i++){
			if(i>0){
				url = url+"&";
			}
				url = url+datas[i]+"="+$("#"+flag+ids[i]).attr("value")+"";
		}
	}else{
		url = data+"="+$("#"+flag+id).attr("value");
	}
	$.ajax({
		contentType : "application/x-www-form-urlencoded; charset=utf-8",
		type : "POST",// 用POST方式传输
		dataType : "json",// 数据格式:JSON
		url : action+".action",// 目标地址
		data : url,
		async: false, 
		error : function(json) {
			alert("jsonerror");
		},
		success : function(json) {
			
		}
	});
}

//富文本框编辑器
function getKindEditor(id ){
	
	$.getScript('kindeditor/kindeditor.js', function() {
		 editor = KindEditor.create('#'+id, {
				cssPath : 'kindeditor/plugins/code/prettify.css',
				uploadJson : 'UploadJsonServlet.do',//'upload_json.jsp',// //,
				width : 580,
				height : 300,
				//fileManagerJson : '../jsp/file_manager_json.jsp',
					items : [
		'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
		'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
		'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
		'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', 
		'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
		'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
		'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
		'anchor', 'link', 'unlink', '|', 'about'
	],
				allowFileManager : false,
	});
		
	});

	
}

//选中所要选的select
function selectedData(selectId , selectedId){
	$("#"+selectId+" option[value='"+$("#"+selectedId).attr("value")+"']").attr('selected',true);
}
//从后台获取字符串解析，tick相应checkbox
function checkedData(checkname , checkedDataId){
	var arr = $("#"+checkedDataId).attr("value").split(",");
	$("input[name='"+checkname+"']").each(function(){
		for(var i = 0 ; i< arr.length; i++){
			var arrid = arr[i].split("<");
			if(arrid[1]==this.value){
				this.checked = true;
			}
		}
	});
}
//隐藏或显示
function objShowOrHide(id){
	if($("#"+id).is(":hidden")){
		$("#"+id).show();
	}else{
		$("#"+id).hide();
	}
	
}

//防止text enter 刷新 
//<input type='text' id='text'  size='10' onkeypress="judge_enter();"/>

function judge_enter(){
    if(window.event.keyCode==13){
         window.event.keyCode = 0;//阻止刷新页面
    }
}

